﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Partial Class renew
    Inherits System.Web.UI.Page

    Private Sub LoadUser(ByRef DropDownToLoad As DropDownList)

        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        objDB.dbVariable.SQLString = "SELECT StaffId,Name FROM AW_Staff WHERE StatusDelete=0 ORDER BY Name"
        objDB.FillData(TempDT, "AW_Staff", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        DropDownToLoad.DataSource = TempDT
        DropDownToLoad.DataTextField = "Name"
        DropDownToLoad.DataValueField = "StaffId"
        DropDownToLoad.DataBind()
        DropDownToLoad.Items.Insert(0, "-SELECT-")
        DropDownToLoad.Items(0).Value = ""

    End Sub

    Private Sub LoadCoBroker()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        objDB.dbVariable.SQLString = "SELECT (Name + '(' + AgencyName + ')') AS Name,CoBrokeId FROM AW_CoBroke ORDER BY Name"
        objDB.FillData(TempDT, "AW_CoBroke", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        Dim NewRow As Data.DataRow
        NewRow = TempDT.NewRow
        NewRow.Item("Name") = "-SELECT-"
        NewRow.Item("CoBrokeId") = Guid.Empty
        TempDT.Rows.InsertAt(NewRow, 0)

        ddlCoBroke.DataSource = TempDT
        ddlCoBroke.DataTextField = "Name"
        ddlCoBroke.DataValueField = "CoBrokeId"
        ddlCoBroke.DataBind()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then

            CBEBack.ConfirmText = "You are about to navigate away from this page. " & vbCrLf & "Changes will be discard!"

            Dim TransactionId As String = ""

            If Session.Item("Tid") Is Nothing Then
                Response.Redirect("transcompletelist.aspx")
            Else

                If Session("StaffId") Is Nothing Then
                    Response.Redirect("Default.aspx")
                ElseIf Session.Item("StaffType").ToString = "2" Then
                    Response.Redirect("Default.aspx")
                Else
                    lblStaffId.Text = Session("StaffId").ToString
                    lblStaffType.Text = Session("StaffType").ToString
                End If



                LoadUser(ddlLister)
                LoadUser(ddlTransactor)
                LoadCoBroker()

                TransactionId = Session.Item("Tid")

                'Getting Property Information
                GetPropertyInformation(TransactionId)
                lblTransId.Text = TransactionId
            End If
        End If
    End Sub

    Private Sub GetPropertyInformation(ByVal TransactionID As String)

        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.dbVariable.SQLString = "SELECT t.TransactionId, t.PropertyId, pt.Type, p.LASF, p.BUSF, t.CoBroke, t.CoBrokeId, c.Name as 'CoBroker', " & _
                                "p.UnitNumber + ', ' + r.Road + ', ' + o.Location + ', ' + s.State + ', ' + y.Country as 'Address', " & _
                                "j.Project, L.StaffId as Lister, L.Name as ListerName, L.Initial as ListerInitial, k.StaffId as Transactor, k.Name as TransactorName, k.Initial as TransactorInitial " & _
                                "FROM AW_RentTransaction t LEFT JOIN AW_Staff L on t.ListerId = L.StaffId LEFT JOIN AW_Staff k on t.TransactorId = k.StaffId " & _
                                "LEFT OUTER JOIN AW_Property p ON p.PropertyId = t.PropertyId LEFT OUTER JOIN AW_CoBroke c ON t.CoBrokeId = c.CoBrokeId " & _
                                "LEFT OUTER JOIN AW_Road r ON p.RoadId = r.RoadId LEFT OUTER JOIN AW_Location o ON r.LocationId = o.LocationId " & _
                                "LEFT OUTER JOIN AW_State s ON o.StateId = s.StateId LEFT OUTER JOIN AW_Country y ON s.CountryId = y.CountryId " & _
                                "LEFT OUTER JOIN AW_Project j ON p.ProjectId = j.ProjectId LEFT OUTER JOIN AW_PropertyType pt ON p.PropertyTypeId = pt.TypeId " & _
                                "WHERE TransactionID=@TransId"
        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(TransactionID))
        objDB.FillData(TempDT, "AW_RentTransaction", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        For Each row As Data.DataRow In TempDT.Rows
            lblAddress.Text = row.Item("Address").ToString
            If row.Item("Project").ToString = "" Then
                TRProject.Visible = False
            Else
                TRProject.Visible = True
                lblProject.Text = row.Item("Project").ToString
            End If
            lblPropertyType.Text = row.Item("Type").ToString
            lblLASQFT.Text = String.Format("{0:#,##0.00}", row.Item("LASF"))
            lblBUSQFT.Text = String.Format("{0:#,##0.00}", row.Item("BUSF"))

            'lblLister.Text = row.Item("ListerName").ToString
            'lblTransactor.Text = row.Item("TransactorName").ToString
            lblLister.Text = row.Item("ListerInitial").ToString
            lblTransactor.Text = row.Item("TransactorInitial").ToString

            If row.Item("CoBroke").ToString = "1" Then
                lblCoBroke.Text = row.Item("CoBroker").ToString
                'For nLoop As Integer = 0 To ddlCoBroke.Items.Count - 1
                '    If ddlCoBroke.Items(nLoop).Value = row.Item("CoBrokeId").ToString Then
                '        ddlCoBroke.SelectedIndex = nLoop
                '        Exit For
                '    End If
                'Next
                ddlCoBroke.SelectedValue = row.Item("CoBrokeId").ToString
                trCoBroke.Visible = True
            Else
                trCoBroke.Visible = False
            End If

            'For nLoop As Integer = 0 To ddlLister.Items.Count - 1
            '    If ddlLister.Items(nLoop).Value = row.Item("Lister").ToString Then
            '        ddlLister.SelectedIndex = nLoop
            '        Exit For
            '    End If
            'Next
            ddlLister.SelectedValue = row.Item("Lister").ToString
            ddlTransactor.SelectedValue = row.Item("Transactor").ToString

            'For nloop As Integer = 0 To ddlTransactor.Items.Count - 1
            '    If ddlTransactor.Items(nloop).Value = row.Item("Transactor").ToString Then
            '        ddlTransactor.SelectedIndex = nloop
            '        Exit For
            '    End If
            'Next
        Next
    End Sub

    Protected Sub btnContinue_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnContinue.Click

        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        'Selecting Current Transaction
        objDB.dbVariable.SQLString = "SELECT PropertyId,LandlordType,LandlordName1,LandlordName2,LandlordName3,LandlordCompany,LandlordNRIC1,LandlordNRIC2,LandlordNRIC3,LandlordCompanyNo, " & _
                                     "LandlordContactPerson,LandlordAddress,LandlordPhone,LandlordMobile,LandlordFax,LandlordEmail,LandLordViewMeetTele,LandlordIncomeTax,LandlordReferral, " & _
                                     "LandlordReferralName,LandlordReferralNRIC,LandlordReferralContact,LandlordReferralStatus,LandlordReferralAmount,LandlordReferralAmtSum,AgencyFee,GST, " & _
                                     "GSTPaidBy,ListingFee,LandlordTAFee,TenantType,TenantName1,TenantName2,TenantName3,TenantCompany,TenantNRIC1,TenantNRIC2,TenantNRIC3,TenantCompanyNo, " & _
                                     "TenantContactPerson,TenantAddress,TenantPhone,TenantMobile,TenantFax,TenantEmail,TenantViewMeetTele,TenantIncomeTax,TenantReferral,TenantReferralName, " & _
                                     "TenantReferralNRIC,TenantReferralContact,TenantReferralStatus,TenantReferralAmount,TenantReferralAmtSum,DisbursementFee,Deposit,DepositMonth,Advance, " & _
                                     "AdvanceMonth,WaterElectric,Tel,TenantTAFee,TransactorId,CoBroke,CoBrokeId,TransactRemark,TransListType,MonthlyRental,TenancyDuration,TenancyDurationType, " & _
                                     "Requisition,TerminationClause,PremiseUse,CreateDate,UpdateDate,UpdateWho,Status,TotalTA,TotalAgencyFee,StampDuty,ListerAmt,ReferralAmt,GovAmt,GrossAmount, " & _
                                     "SignDate,SignRemark,SignComplete,SignCompleteBy,SignCompleteDate,CommencementDate,RentFreePeriod,RentFreePeriodType,CollectDate,CollectAmt,CollectRemark, " & _
                                     "CollectComplete,CollectCompleteBy,CollectCompleteDate " & _
                                     "FROM AW_RentTransaction WHERE TransactionId=@TransactionId"
        objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransId.Text))
        objDB.FillData(TempDT, "AW_RentTransaction", Database.SQLCommandType.NormalString)

        'Begin Creating a New Transaction ROW and Update AW_Property with RTransactionId and RListerId and RListStatus = NULL and RRelistStatus = 0 and
        objDB.dbVariable.SQLString = "INSERT INTO AW_RentTransaction (TransactionId,ListerId,ListDate,PropertyId,LandlordType,LandlordName1,LandlordName2,LandlordName3,LandlordCompany,LandlordNRIC1,LandlordNRIC2,LandlordNRIC3,LandlordCompanyNo, " & _
                                     "LandlordContactPerson,LandlordAddress,LandlordPhone,LandlordMobile,LandlordFax,LandlordEmail,LandLordViewMeetTele,LandlordIncomeTax,LandlordReferral, " & _
                                     "LandlordReferralName,LandlordReferralNRIC,LandlordReferralContact,LandlordReferralStatus,LandlordReferralAmount,LandlordReferralAmtSum,AgencyFee,GST, " & _
                                     "GSTPaidBy,ListingFee,LandlordTAFee,TenantType,TenantName1,TenantName2,TenantName3,TenantCompany,TenantNRIC1,TenantNRIC2,TenantNRIC3,TenantCompanyNo, " & _
                                     "TenantContactPerson,TenantAddress,TenantPhone,TenantMobile,TenantFax,TenantEmail,TenantViewMeetTele,TenantIncomeTax,TenantReferral,TenantReferralName, " & _
                                     "TenantReferralNRIC,TenantReferralContact,TenantReferralStatus,TenantReferralAmount,TenantReferralAmtSum,DisbursementFee,Deposit,DepositMonth,Advance, " & _
                                     "AdvanceMonth,WaterElectric,Tel,TenantTAFee,TransactorId,TransactDate,CoBroke,CoBrokeId,TransactRemark,TransListType,MonthlyRental,TenancyDuration,TenancyDurationType, " & _
                                     "Requisition,TerminationClause,PremiseUse,CreateDate,UpdateDate,UpdateWho,Status,TotalTA,TotalAgencyFee,StampDuty,ListerAmt,ReferralAmt,GovAmt,GrossAmount, " & _
                                     "SignDate,SignRemark,SignComplete,SignCompleteBy,SignCompleteDate,CommencementDate,RentFreePeriod,RentFreePeriodType,CollectDate,CollectAmt,CollectRemark, " & _
                                     "CollectComplete,CollectCompleteBy,CollectCompleteDate,Renewed) VALUES " & _
                                     "(@TransactionId,@ListerId,@ListDate,@PropertyId,@LandlordType,@LandlordName1,@LandlordName2,@LandlordName3,@LandlordCompany,@LandlordNRIC1,@LandlordNRIC2,@LandlordNRIC3,@LandlordCompanyNo, " & _
                                     "@LandlordContactPerson,@LandlordAddress,@LandlordPhone,@LandlordMobile,@LandlordFax,@LandlordEmail,@LandLordViewMeetTele,@LandlordIncomeTax,@LandlordReferral, " & _
                                     "@LandlordReferralName,@LandlordReferralNRIC,@LandlordReferralContact,@LandlordReferralStatus,@LandlordReferralAmount,@LandlordReferralAmtSum,@AgencyFee,@GST, " & _
                                     "@GSTPaidBy,@ListingFee,@LandlordTAFee,@TenantType,@TenantName1,@TenantName2,@TenantName3,@TenantCompany,@TenantNRIC1,@TenantNRIC2,@TenantNRIC3,@TenantCompanyNo, " & _
                                     "@TenantContactPerson,@TenantAddress,@TenantPhone,@TenantMobile,@TenantFax,@TenantEmail,@TenantViewMeetTele,@TenantIncomeTax,@TenantReferral,@TenantReferralName, " & _
                                     "@TenantReferralNRIC,@TenantReferralContact,@TenantReferralStatus,@TenantReferralAmount,@TenantReferralAmtSum,@DisbursementFee,@Deposit,@DepositMonth,@Advance, " & _
                                     "@AdvanceMonth,@WaterElectric,@Tel,@TenantTAFee,@TransactorId,@TransactDate,@CoBroke,@CoBrokeId,@TransactRemark,@TransListType,@MonthlyRental,@TenancyDuration,@TenancyDurationType, " & _
                                     "@Requisition,@TerminationClause,@PremiseUse,@CreateDate,@UpdateDate,@UpdateWho,@Status,@TotalTA,@TotalAgencyFee,@StampDuty,@ListerAmt,@ReferralAmt,@GovAmt,@GrossAmount, " & _
                                     "@SignDate,@SignRemark,@SignComplete,@SignCompleteBy,@SignCompleteDate,@CommencementDate,@RentFreePeriod,@RentFreePeriodType,@CollectDate,@CollectAmt,@CollectRemark, " & _
                                     "@CollectComplete,@CollectCompleteBy,@CollectCompleteDate,@Renewed)"
        Dim TransactorId As String = ddlTransactor.SelectedValue
        Dim ListerId As String = ddlLister.SelectedValue
        Dim TransactionId As Guid = Guid.NewGuid
        Dim PropertyId As String = Guid.Empty.ToString
        Dim TransListType As String = String.Empty

        For Each ReadRow As Data.DataRow In TempDT.Rows
            objDB.ClearParameter()
            objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, TransactionId)
            objDB.AddParameter("ListerId", Data.SqlDbType.UniqueIdentifier, New Guid(ListerId))
            objDB.AddParameter("ListDate", Data.SqlDbType.DateTime, Now)
            objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, ReadRow.Item("PropertyId"))
            PropertyId = ReadRow.Item("PropertyId").ToString
            objDB.AddParameter("LandlordType", Data.SqlDbType.TinyInt, ReadRow.Item("LandlordType"))
            objDB.AddParameter("LandlordName1", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordName1"))
            objDB.AddParameter("LandlordName2", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordName2"))
            objDB.AddParameter("LandlordName3", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordName3"))
            objDB.AddParameter("LandlordCompany", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordCompany"))
            objDB.AddParameter("LandlordNRIC1", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordNRIC1"))
            objDB.AddParameter("LandlordNRIC2", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordNRIC2"))
            objDB.AddParameter("LandlordNRIC3", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordNRIC3"))
            objDB.AddParameter("LandlordCompanyNo", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordCompanyNo"))
            objDB.AddParameter("LandlordContactPerson", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordContactPerson"))
            objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordAddress"))
            objDB.AddParameter("LandlordPhone", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordPhone"))
            objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordMobile"))
            objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordFax"))
            objDB.AddParameter("LandlordEmail", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordEmail"))
            objDB.AddParameter("LandLordViewMeetTele", Data.SqlDbType.NVarChar, ReadRow.Item("LandLordViewMeetTele"))
            objDB.AddParameter("LandlordIncomeTax", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordIncomeTax"))
            objDB.AddParameter("LandlordReferral", Data.SqlDbType.TinyInt, ReadRow.Item("LandlordReferral"))
            objDB.AddParameter("LandlordReferralName", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordReferralName"))
            objDB.AddParameter("LandlordReferralNRIC", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordReferralNRIC"))
            objDB.AddParameter("LandlordReferralContact", Data.SqlDbType.NVarChar, ReadRow.Item("LandlordReferralContact"))
            objDB.AddParameter("LandlordReferralStatus", Data.SqlDbType.TinyInt, ReadRow.Item("LandlordReferralStatus"))
            objDB.AddParameter("LandlordReferralAmount", Data.SqlDbType.Decimal, ReadRow.Item("LandlordReferralAmount"))
            objDB.AddParameter("LandlordReferralAmtSum", Data.SqlDbType.Decimal, ReadRow.Item("LandlordReferralAmtSum"))
            objDB.AddParameter("AgencyFee", Data.SqlDbType.Decimal, ReadRow.Item("AgencyFee"))
            objDB.AddParameter("GST", Data.SqlDbType.Decimal, ReadRow.Item("GST"))
            objDB.AddParameter("GSTPaidBy", Data.SqlDbType.TinyInt, ReadRow.Item("GSTPaidBy"))
            objDB.AddParameter("ListingFee", Data.SqlDbType.Decimal, ReadRow.Item("ListingFee"))
            objDB.AddParameter("LandlordTAFee", Data.SqlDbType.Decimal, ReadRow.Item("LandlordTAFee"))
            objDB.AddParameter("TenantType", Data.SqlDbType.TinyInt, ReadRow.Item("TenantType"))
            objDB.AddParameter("TenantName1", Data.SqlDbType.NVarChar, ReadRow.Item("TenantName1"))
            objDB.AddParameter("TenantName2", Data.SqlDbType.NVarChar, ReadRow.Item("TenantName2"))
            objDB.AddParameter("TenantName3", Data.SqlDbType.NVarChar, ReadRow.Item("TenantName3"))
            objDB.AddParameter("TenantCompany", Data.SqlDbType.NVarChar, ReadRow.Item("TenantCompany"))
            objDB.AddParameter("TenantNRIC1", Data.SqlDbType.NVarChar, ReadRow.Item("TenantNRIC1"))
            objDB.AddParameter("TenantNRIC2", Data.SqlDbType.NVarChar, ReadRow.Item("TenantNRIC2"))
            objDB.AddParameter("TenantNRIC3", Data.SqlDbType.NVarChar, ReadRow.Item("TenantNRIC3"))
            objDB.AddParameter("TenantCompanyNo", Data.SqlDbType.NVarChar, ReadRow.Item("TenantCompanyNo"))
            objDB.AddParameter("TenantContactPerson", Data.SqlDbType.NVarChar, ReadRow.Item("TenantContactPerson"))
            objDB.AddParameter("TenantAddress", Data.SqlDbType.NVarChar, ReadRow.Item("TenantAddress"))
            objDB.AddParameter("TenantPhone", Data.SqlDbType.NVarChar, ReadRow.Item("TenantPhone"))
            objDB.AddParameter("TenantMobile", Data.SqlDbType.NVarChar, ReadRow.Item("TenantMobile"))
            objDB.AddParameter("TenantFax", Data.SqlDbType.NVarChar, ReadRow.Item("TenantFax"))
            objDB.AddParameter("TenantEmail", Data.SqlDbType.NVarChar, ReadRow.Item("TenantEmail"))
            objDB.AddParameter("TenantViewMeetTele", Data.SqlDbType.NVarChar, ReadRow.Item("TenantViewMeetTele"))
            objDB.AddParameter("TenantIncomeTax", Data.SqlDbType.NVarChar, ReadRow.Item("TenantIncomeTax"))
            objDB.AddParameter("TenantReferral", Data.SqlDbType.TinyInt, ReadRow.Item("TenantReferral"))
            objDB.AddParameter("TenantReferralName", Data.SqlDbType.NVarChar, ReadRow.Item("TenantReferralName"))
            objDB.AddParameter("TenantReferralNRIC", Data.SqlDbType.NVarChar, ReadRow.Item("TenantReferralNRIC"))
            objDB.AddParameter("TenantReferralContact", Data.SqlDbType.NVarChar, ReadRow.Item("TenantReferralContact"))
            objDB.AddParameter("TenantReferralStatus", Data.SqlDbType.TinyInt, ReadRow.Item("TenantReferralStatus"))
            objDB.AddParameter("TenantReferralAmount", Data.SqlDbType.Decimal, ReadRow.Item("TenantReferralAmount"))
            objDB.AddParameter("TenantReferralAmtSum", Data.SqlDbType.Decimal, ReadRow.Item("TenantReferralAmtSum"))
            objDB.AddParameter("DisbursementFee", Data.SqlDbType.Decimal, ReadRow.Item("DisbursementFee"))
            objDB.AddParameter("Deposit", Data.SqlDbType.Decimal, ReadRow.Item("Deposit"))
            objDB.AddParameter("DepositMonth", Data.SqlDbType.Decimal, ReadRow.Item("DepositMonth"))
            objDB.AddParameter("Advance", Data.SqlDbType.Decimal, ReadRow.Item("Advance"))
            objDB.AddParameter("AdvanceMonth", Data.SqlDbType.Decimal, ReadRow.Item("AdvanceMonth"))
            objDB.AddParameter("WaterElectric", Data.SqlDbType.Decimal, ReadRow.Item("WaterElectric"))
            objDB.AddParameter("Tel", Data.SqlDbType.Decimal, ReadRow.Item("Tel"))
            objDB.AddParameter("TenantTAFee", Data.SqlDbType.Decimal, ReadRow.Item("TenantTAFee"))
            objDB.AddParameter("TransactorId", Data.SqlDbType.UniqueIdentifier, New Guid(TransactorId))
            objDB.AddParameter("TransactDate", Data.SqlDbType.DateTime, Now)
            If ddlCoBroke.SelectedIndex = 0 Then
                objDB.AddParameter("CoBroke", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("CoBrokeId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            Else
                objDB.AddParameter("CoBroke", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("CoBrokeId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlCoBroke.SelectedValue))
            End If
            objDB.AddParameter("TransactRemark", Data.SqlDbType.NVarChar, txtRemark.Text.Trim)
            objDB.AddParameter("TransListType", Data.SqlDbType.TinyInt, ReadRow.Item("TransListType"))
            objDB.AddParameter("MonthlyRental", Data.SqlDbType.Decimal, ReadRow.Item("MonthlyRental"))
            objDB.AddParameter("TenancyDuration", Data.SqlDbType.Decimal, ReadRow.Item("TenancyDuration"))
            objDB.AddParameter("TenancyDurationType", Data.SqlDbType.TinyInt, ReadRow.Item("TenancyDurationType"))
            objDB.AddParameter("Requisition", Data.SqlDbType.NVarChar, ReadRow.Item("Requisition"))
            objDB.AddParameter("TerminationClause", Data.SqlDbType.NVarChar, ReadRow.Item("TerminationClause"))
            objDB.AddParameter("PremiseUse", Data.SqlDbType.TinyInt, ReadRow.Item("PremiseUse"))
            objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now)
            objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, Now)
            objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffId.Text))
            objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 0)
            objDB.AddParameter("TotalTA", Data.SqlDbType.Decimal, ReadRow.Item("TotalTA"))
            objDB.AddParameter("TotalAgencyFee", Data.SqlDbType.Decimal, ReadRow.Item("TotalAgencyFee"))
            objDB.AddParameter("StampDuty", Data.SqlDbType.Decimal, ReadRow.Item("StampDuty"))
            objDB.AddParameter("ListerAmt", Data.SqlDbType.Decimal, ReadRow.Item("ListerAmt"))
            objDB.AddParameter("ReferralAmt", Data.SqlDbType.Decimal, ReadRow.Item("ReferralAmt"))
            objDB.AddParameter("GovAmt", Data.SqlDbType.Decimal, ReadRow.Item("GovAmt"))
            objDB.AddParameter("GrossAmount", Data.SqlDbType.Decimal, ReadRow.Item("GrossAmount"))
            objDB.AddParameter("SignDate", Data.SqlDbType.DateTime, DBNull.Value)
            objDB.AddParameter("SignRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("SignComplete", Data.SqlDbType.TinyInt, DBNull.Value)
            objDB.AddParameter("SignCompleteBy", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            objDB.AddParameter("SignCompleteDate", Data.SqlDbType.DateTime, DBNull.Value)
            objDB.AddParameter("CommencementDate", Data.SqlDbType.DateTime, DBNull.Value)
            objDB.AddParameter("RentFreePeriod", Data.SqlDbType.Int, DBNull.Value)
            objDB.AddParameter("RentFreePeriodType", Data.SqlDbType.TinyInt, DBNull.Value)
            objDB.AddParameter("CollectDate", Data.SqlDbType.DateTime, DBNull.Value)
            objDB.AddParameter("CollectAmt", Data.SqlDbType.Decimal, DBNull.Value)
            objDB.AddParameter("CollectRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("CollectComplete", Data.SqlDbType.TinyInt, DBNull.Value)
            objDB.AddParameter("CollectCompleteBy", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            objDB.AddParameter("CollectCompleteDate", Data.SqlDbType.DateTime, DBNull.Value)
            objDB.AddParameter("Renewed", Data.SqlDbType.TinyInt, 1)
            TransListType = ReadRow.Item("TransListType").ToString
        Next

        Try
            objDB.OpenConnection()
            objDB.InitDbTrans()
            objDB.ExecuteQuery(False)

            Dim OId As Guid = Guid.NewGuid
            InsertTrans_Old(TransactionId.ToString, OId.ToString, "", objDB)

            objDB.dbVariable.SQLString = "UPDATE AW_RentTransaction SET Status=5 WHERE TransactionId=@TransactionId"
            objDB.ClearParameter()
            objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransId.Text))
            'edited by minginn @ 13/6/2011 - add in to differentiate trans from renew button or transact
            objDB.AddParameter("Renewed", Data.SqlDbType.TinyInt, 1)
            objDB.ExecuteQuery(False)
            InsertTrans_Old(lblTransId.Text, "", "5", objDB)

            'edited by minginn @ 13/6/2011 - to update the createdate date for type
            Dim sqlAdditional As String
            objDB.ClearParameter()
            Select Case TransListType
                Case "1" '--RR
                    sqlAdditional = ", RRCreateDate=@RRCreateDate, RCAmt=@RCAmt, RCPSF=@RCPSF, RCAskAmt=@RCAskAmt, " & _
                                    "RCAskPSF=@RCAskPSF, RCCreateDate=@RCCreateDate, RCYes=@RCYes, " & _
                                    "RLAmt=@RLAmt, RLPSF=@RLPSF, RLAskAmt=@RLAskAmt, RLAskPSF=@RLAskPSF, RLCreateDate=@RLCreateDate, RLYes=@RLYes, " & _
                                    "RIAmt=@RIAmt, RIPSF=@RIPSF, RIAskAmt=@RIAskAmt, RIAskPSF=@RIAskPSF, RICreateDate=@RICreateDate, RIYes=@RIYes "
                    objDB.AddParameter("RRCreateDate", Data.SqlDbType.DateTime, Now())
                    'Other than that all reset to null
                    objDB.AddParameter("RCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RCYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RLYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RIYes", Data.SqlDbType.TinyInt, 0)
                Case "2" '--RC
                    sqlAdditional = ", RCCreateDate=@RCCreateDate, RRAmt=@RRAmt, RRPSF=@RRPSF, RRAskAmt=@RRAskAmt, " & _
                                     "RRAskPSF=@RRAskPSF, RRCreateDate=@RRCreateDate, RRYes=@RRYes, " & _
                                     "RLAmt=@RLAmt, RLPSF=@RLPSF, RLAskAmt=@RLAskAmt, RLAskPSF=@RLAskPSF, RLCreateDate=@RLCreateDate, RLYes=@RLYes, " & _
                                     "RIAmt=@RIAmt, RIPSF=@RIPSF, RIAskAmt=@RIAskAmt, RIAskPSF=@RIAskPSF, RICreateDate=@RICreateDate, RIYes=@RIYes "
                    objDB.AddParameter("RCCreateDate", Data.SqlDbType.DateTime, Now())
                    'Other than that all reset to null
                    objDB.AddParameter("RRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RRYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RLYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RIYes", Data.SqlDbType.TinyInt, 0)
                Case "3" '--RL
                    sqlAdditional = ", RLCreateDate=@RLCreateDate, RRAmt=@RRAmt, RRPSF=@RRPSF, RRAskAmt=@RRAskAmt, " & _
                                    "RRAskPSF=@RRAskPSF, RRCreateDate=@RRCreateDate, RRYes=@RRYes, " & _
                                    "RCAmt=@RCAmt, RCPSF=@RCPSF, RCAskAmt=@RCAskAmt, RCAskPSF=@RCAskPSF, RCCreateDate=@RCCreateDate, RCYes=@RCYes, " & _
                                    "RIAmt=@RIAmt, RIPSF=@RIPSF, RIAskAmt=@RIAskAmt, RIAskPSF=@RIAskPSF, RICreateDate=@RICreateDate, RIYes=@RIYes "
                    objDB.AddParameter("RLCreateDate", Data.SqlDbType.DateTime, Now())
                    'Other than that all reset to null
                    objDB.AddParameter("RRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RRYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RCYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RIYes", Data.SqlDbType.TinyInt, 0)
                Case "4" '--RI
                    sqlAdditional = ", RICreateDate=@RICreateDate, RRAmt=@RRAmt, RRPSF=@RRPSF, RRAskAmt=@RRAskAmt, " & _
                                   "RRAskPSF=@RRAskPSF, RRCreateDate=@RRCreateDate, RRYes=@RRYes, " & _
                                   "RCAmt=@RCAmt, RCPSF=@RCPSF, RCAskAmt=@RCAskAmt, RCAskPSF=@RCAskPSF, RCCreateDate=@RCCreateDate, RCYes=@RCYes, " & _
                                   "RLAmt=@RLAmt, RLPSF=@RLPSF, RLAskAmt=@RLAskAmt, RLAskPSF=@RLAskPSF, RLCreateDate=@RLCreateDate, RLYes=@RLYes "
                    objDB.AddParameter("RICreateDate", Data.SqlDbType.DateTime, Now())
                    'Other than that all reset to null
                    objDB.AddParameter("RRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RRYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RCYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RLYes", Data.SqlDbType.TinyInt, 0)
                Case Else
                    sqlAdditional = ", RIAmt=@RIAmt, RIPSF=@RIPSF, RIAskAmt=@RIAskAmt, RIAskPSF=@RIAskPSF, RIYes=@RIYes, " & _
                                    "RICreateDate=@RICreateDate, RRAmt=@RRAmt, RRPSF=@RRPSF, RRAskAmt=@RRAskAmt, " & _
                                    "RRAskPSF=@RRAskPSF, RRCreateDate=@RRCreateDate, RRYes=@RRYes, " & _
                                    "RCAmt=@RCAmt, RCPSF=@RCPSF, RCAskAmt=@RCAskAmt, RCAskPSF=@RCAskPSF, RCCreateDate=@RCCreateDate, RCYes=@RCYes, " & _
                                    "RLAmt=@RLAmt, RLPSF=@RLPSF, RLAskAmt=@RLAskAmt, RLAskPSF=@RLAskPSF, RLCreateDate=@RLCreateDate, RLYes=@RLYes "
                    objDB.AddParameter("RIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RIYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RRYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RCYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RLYes", Data.SqlDbType.TinyInt, 0)
            End Select

            objDB.dbVariable.SQLString = "UPDATE AW_Property SET RTransactionId=@RTransactionId, RListerId=@RListerId, RRelistStatus=@RRelistStatus, " & _
                                        "RListStatus=@RListStatus, UpdateDate=@UpdateDate, UpdateWho=@UpdateWho, CreateDate=@CreateDate" & sqlAdditional & "WHERE PropertyId=@PropertyId"
            objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(PropertyId))
            objDB.AddParameter("RTransactionId", Data.SqlDbType.UniqueIdentifier, TransactionId)
            objDB.AddParameter("RListerId", Data.SqlDbType.UniqueIdentifier, New Guid(ListerId))
            objDB.AddParameter("RRelistStatus", Data.SqlDbType.TinyInt, 1)
            objDB.AddParameter("RListStatus", Data.SqlDbType.TinyInt, DBNull.Value)
            objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, DBNull.Value)
            objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
            objDB.ExecuteQuery(False)
            InsertIntoProperty_Old(PropertyId, TransactionId.ToString, ListerId, objDB)
            objDB.DbTransCommit()
            objDB.CloseConnection()
            Session.Add("Tid", TransactionId.ToString)
            Session.Add("Oid", OId.ToString)
            Response.Redirect("rtrans.aspx", True)
        Catch ex As Exception
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.DbTransRollback()
                objDB.CloseConnection()
            End If
            divError.Visible = True
            lblMsgError.Text = "There is an error with the following message <br /> " & ex.Message
            lblMsgError.Visible = True
        End Try


    End Sub

    Private Sub InsertIntoProperty_Old(ByVal PropertyId As String, ByVal TransactionId As String, ByVal ListerId As String, ByVal objdb As Database)

        objdb.dbVariable.SQLString = "INSERT INTO " + AppSettings("logdatasource").ToString() + ".dbo.AW_Property " & _
            "(PropertyId, RoadId, ProjectId, PropertyTypeId, UnitNumber, ListType, STransactionId, RTransactionId, SRAmt, " & _
            "SRPSF, SRAskAmt, SRAskPSF, SRCreateDate, SRYes, SCAmt, SCPSF, SCAskAmt, SCAskPSF, SCCreateDate, SCYes, SLAmt, " & _
            "SLPSF, SLAskAmt, SLAskPSF, SLCreateDate, SLYes, SIAmt, SIPSF, SIAskAmt, SIAskPSF, SICreateDate, SIYes, RRAmt, " & _
            "RRPSF, RRAskAmt, RRAskPSF, RRCreateDate, RRYes, RCAmt, RCPSF, RCAskAmt, RCAskPSF, RCCreateDate, RCYes, RLAmt, " & _
            "RLPSF, RLAskAmt, RLAskPSF, RLCreateDate, RLYes, RIAmt, RIPSF, RIAskAmt, RIAskPSF, RICreateDate, RIYes, " & _
            "SListerId, RListerId, KeyInOffice, ProjectRemark, PropertyDesc, SignboardStatus, SignboardWhere, SignboardWhen, " & _
            "SurveySheet, QuitRent, AssessmentBill, PendingStatus, PendingWho, PendingWhen, PendingWhy, Tenure, ListHoldExpired, " & _
            "Access, AccessRemark, Condition, ConditionRemark, Facing, Zoning, ZoningRemark, Room, Bathroom, BestBuy, ExclusiveStatus, ExclusiveWho, ExclusiveWhen, ExclusiveEndDate, " & _
            "AuthorizeSaleRent, Remark, Production1, Production2, Production3, Admin1, Admin2, Admin3, LAWidth, LALength, " & _
            "LASF, BUWidth, BULength, BUSF, FloorLoad, SECMK, Ceiling, Terrain, District, Lot, Phase, Furnished, FurnishedRemark, " & _
            "Renovated, RenovatedRemark, Developer, OwnerName, OwnerMobile, OwnerPhone, OwnerFax, OwnerEmail, " & _
            "OwnerAddress, ReferLister, SListStatus, RListStatus, SRelistStatus, RRelistStatus, CreateDate, StatusDelete, UpdateDate, UpdateWho, " & _
            "LandlordName, LandlordMobile, LandlordPhone, LandlordFax, LandlordEmail, LandlordAddress, ReferLandlordLister) " & _
            "SELECT PropertyId, RoadId, ProjectId, PropertyTypeId, UnitNumber, ListType, STransactionId, @RTransactionIdOLD, SRAmt, " & _
            "SRPSF, SRAskAmt, SRAskPSF, SRCreateDate, SRYes, SCAmt, SCPSF, SCAskAmt, SCAskPSF, SCCreateDate, SCYes, SLAmt, " & _
            "SLPSF, SLAskAmt, SLAskPSF, SLCreateDate, SLYes, SIAmt, SIPSF, SIAskAmt, SIAskPSF, SICreateDate, SIYes, RRAmt, " & _
            "RRPSF, RRAskAmt, RRAskPSF, RRCreateDate, RRYes, RCAmt, RCPSF, RCAskAmt, RCAskPSF, RCCreateDate, RCYes, RLAmt, " & _
            "RLPSF, RLAskAmt, RLAskPSF, RLCreateDate, RLYes, RIAmt, RIPSF, RIAskAmt, RIAskPSF, RICreateDate, RIYes, " & _
            "SListerId, @RListerIdOLD, KeyInOffice, ProjectRemark, PropertyDesc, SignboardStatus, SignboardWhere, SignboardWhen, " & _
            "SurveySheet, QuitRent, AssessmentBill, PendingStatus, PendingWho, PendingWhen, PendingWhy, Tenure, ListHoldExpired, " & _
            "Access, AccessRemark, Condition, ConditionRemark, Facing, Zoning, ZoningRemark, Room, Bathroom, BestBuy, ExclusiveStatus, ExclusiveWho, ExclusiveWhen, ExclusiveEndDate, " & _
            "AuthorizeSaleRent, Remark, Production1, Production2, Production3, Admin1, Admin2, Admin3, LAWidth, LALength, " & _
            "LASF, BUWidth, BULength, BUSF, FloorLoad, SECMK, Ceiling, Terrain, District, Lot, Phase, Furnished, FurnishedRemark, " & _
            "Renovated, RenovatedRemark, Developer, OwnerName, OwnerMobile, OwnerPhone, OwnerFax, OwnerEmail, " & _
            "OwnerAddress, ReferLister, SListStatus, @RListStatusOLD, SRelistStatus, @RRelistStatusOLD, @CreateDateOLD, StatusDelete, @UpdateDateOLD, @UpdateWhoOLD, " & _
            "LandlordName, LandlordMobile, LandlordPhone, LandlordFax, LandlordEmail, LandlordAddress, ReferLandlordLister " & _
            "FROM AW_Property WHERE PropertyId = @PropertyIdOLD"

        objdb.AddParameter("PropertyIdOLD", Data.SqlDbType.UniqueIdentifier, New Guid(PropertyId))
        objdb.AddParameter("RTransactionIdOLD", Data.SqlDbType.UniqueIdentifier, New Guid(TransactionId))
        objdb.AddParameter("RListerIdOLD", Data.SqlDbType.UniqueIdentifier, New Guid(ListerId))
        objdb.AddParameter("RRelistStatusOLD", Data.SqlDbType.TinyInt, 1)
        objdb.AddParameter("RListStatusOLD", Data.SqlDbType.TinyInt, DBNull.Value)
        objdb.AddParameter("CreateDateOLD", Data.SqlDbType.DateTime, Now())
        objdb.AddParameter("UpdateDateOLD", Data.SqlDbType.DateTime, DBNull.Value)
        objdb.AddParameter("UpdateWhoOLD", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffId.Text))
        objdb.ExecuteQuery(False)

    End Sub

    Private Sub InsertTrans_Old(ByVal TransId As String, ByVal OId As String, ByVal Status As String, ByVal objDB As Database)
        Dim strStatus As String = String.Empty
        If Status <> "" Then
            strStatus = " @Status, "
            objDB.AddParameter("Status", Data.SqlDbType.TinyInt, Status)
        Else
            strStatus = " Status, "
        End If

        objDB.dbVariable.SQLString = "INSERT INTO " + AppSettings("logdatasource").ToString() + ".dbo.AW_RentTransaction (OId, TransactionId, PropertyId, InvoiceNumber, OpenFileRef, CloseFileRef, ListerId, ListDate, " & _
                    "LandlordType, LandlordName1, LandlordName2, LandlordName3, LandlordCompany, LandlordNRIC1, LandlordNRIC2, LandlordNRIC3, LandlordCompanyNo, " & _
                    "LandlordContactPerson, LandlordAddress, LandlordPhone, LandlordMobile, LandlordFax, LandlordEmail, LandlordViewMeetTele, LandlordIncomeTax, " & _
                    "LandlordReferral, LandlordReferralName, LandlordReferralNRIC, LandlordReferralContact, LandlordReferralStatus, LandlordReferralAmount, " & _
                    "LandlordReferralAmtSum, AgencyFee, GST, GSTPaidBy, ListingFee, LandlordTAFee, TenantType, TenantName1, TenantName2, TenantName3, TenantCompany, " & _
                    "TenantNRIC1, TenantNRIC2, TenantNRIC3, TenantCompanyNo, TenantContactPerson, TenantAddress, TenantPhone, TenantMobile, TenantFax, TenantEmail, " & _
                    "TenantViewMeetTele, TenantIncomeTax, TenantReferral, TenantReferralName, TenantReferralNRIC, TenantReferralContact, TenantReferralStatus, " & _
                    "TenantReferralAmount, TenantReferralAmtSum, DisbursementFee, Deposit, DepositMonth, Advance, AdvanceMonth, WaterElectric, Tel, TenantTAFee, " & _
                    "TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, TransListType, MonthlyRental, TenancyDuration, TenancyDurationType, Requisition, " & _
                    "TerminationClause, PremiseUse, CreateDate, UpdateDate, UpdateWho, Status, Renewed, TotalTA, TotalAgencyFee, StampDuty, ListerAmt, ReferralAmt, " & _
                    "GovAmt, GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, SignCompleteDate, CommencementDate, RentFreePeriod, RentFreePeriodType, " & _
                    "CollectDate, CollectAmt, CollectRemark, CollectComplete, CollectCompleteBy, CollectCompleteDate, UndoDate, UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, " & _
                    "UndoGST, UndoGSTPaidBy, UndoListerAmt) SELECT @OId, TransactionId, PropertyId, InvoiceNumber, OpenFileRef, CloseFileRef, ListerId, ListDate, " & _
                    "LandlordType, LandlordName1, LandlordName2, LandlordName3, LandlordCompany, LandlordNRIC1, LandlordNRIC2, LandlordNRIC3, LandlordCompanyNo, " & _
                    "LandlordContactPerson, LandlordAddress, LandlordPhone, LandlordMobile, LandlordFax, LandlordEmail, LandlordViewMeetTele, LandlordIncomeTax, " & _
                    "LandlordReferral, LandlordReferralName, LandlordReferralNRIC, LandlordReferralContact, LandlordReferralStatus, LandlordReferralAmount, " & _
                    "LandlordReferralAmtSum, AgencyFee, GST, GSTPaidBy, ListingFee, LandlordTAFee, TenantType, TenantName1, TenantName2, TenantName3, TenantCompany, " & _
                    "TenantNRIC1, TenantNRIC2, TenantNRIC3, TenantCompanyNo, TenantContactPerson, TenantAddress, TenantPhone, TenantMobile, TenantFax, TenantEmail, " & _
                    "TenantViewMeetTele, TenantIncomeTax, TenantReferral, TenantReferralName, TenantReferralNRIC, TenantReferralContact, TenantReferralStatus, " & _
                    "TenantReferralAmount, TenantReferralAmtSum, DisbursementFee, Deposit, DepositMonth, Advance, AdvanceMonth, WaterElectric, Tel, TenantTAFee, " & _
                    "TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, TransListType, MonthlyRental, TenancyDuration, TenancyDurationType, Requisition, " & _
                    "TerminationClause, PremiseUse, @CreateDateOLD, @UpdateDateOLD, @UpdateWhoOLD," & strStatus & " Renewed, TotalTA, TotalAgencyFee, StampDuty, ListerAmt, ReferralAmt, " & _
                    "GovAmt, GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, SignCompleteDate, CommencementDate, RentFreePeriod, RentFreePeriodType, " & _
                    "CollectDate, CollectAmt, CollectRemark, CollectComplete, CollectCompleteBy, CollectCompleteDate, UndoDate, UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, " & _
                    "UndoGST, UndoGSTPaidBy, UndoListerAmt FROM AW_RentTransaction WHERE TransactionId=@TransId"

        objDB.AddParameter("CreateDateOLD", Data.SqlDbType.DateTime, Now())
        objDB.AddParameter("UpdateDateOLD", Data.SqlDbType.DateTime, DBNull.Value)
        objDB.AddParameter("UpdateWhoOLD", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffId.Text.Trim))
        If OId = "" Then
            objDB.AddParameter("OId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
        Else
            objDB.AddParameter("OId", Data.SqlDbType.UniqueIdentifier, New Guid(OId))
        End If

        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(TransId))

        objDB.ExecuteQuery(False)
    End Sub

    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
        Dim strBack As String = Session("Back").ToString
        Dim arr() As String = strBack.Split("ڡ")
        Response.Redirect(arr(0).ToString)
    End Sub
End Class
